package com.cn.shine.controller;

import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.shine.common.Constant;
import com.cn.shine.common.DataBean;
import com.cn.shine.pojo.Customer;
import com.cn.shine.service.CustomerService;
import com.cn.shine.service.OrderService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

@Controller
@RequestMapping("/report")
public class ReportController {
    
    @Resource
    private CustomerService customerService;
    @Resource
    private OrderService orderService;
    @RequestMapping("/custReport")
    private String custReport(){
        return "report";
    }
    @RequestMapping("/customerReport")
    @ResponseBody
    public JSONObject customerReport(){
        List<Customer> list = customerService.customerReport();
        DataBean bean = new DataBean();
        Gson gson = new GsonBuilder().create();
        bean.setData(gson.toJson(list));
        bean.setMsg(Constant.QUERY_SUCCESS);
        bean.setResult(Constant.SUCCESS);
        JSONObject obj = JSONObject.fromObject(bean);
        return obj;
    }
    
    @RequestMapping("/orderReport")
    @ResponseBody
    public JSONObject orderReport(){
        List<Customer> list = customerService.orderReport();
        String payAvg=orderService.getAvgPay();
        DataBean bean = new DataBean();
        Gson gson = new GsonBuilder().create();
        bean.setData(gson.toJson(list));
        bean.setMsg(Constant.QUERY_SUCCESS);
        bean.setResult(Constant.SUCCESS);
        JSONObject obj = JSONObject.fromObject(bean);
        obj.put("payAvg", payAvg);
        return obj;
    }
}
